package com.orange.delivery.presentation.common;

import org.apache.wicket.Page;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.panel.Panel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.francetelecom.clara.component.wicket.app.menus.OMenuBar;
import com.orange.delivery.presentation.page.HomePage;
import com.orange.delivery.presentation.page.MarketPage;

/**
 * Create {@link HeaderTabPanel} contain the tabs available in result pages
 */

public class HeaderTabPanel extends Panel {

	private static final long serialVersionUID = 1L;

	private static final Logger LOG = LoggerFactory.getLogger(HeaderPanel.class.getName());

	public HeaderTabPanel(String id) {
		super(id);
		createPanelComponents();
	}

	/**
	 * Create one {@link WebMarkupContainer} for each tab defined in TabList Add a {@link Link} on each
	 */
	private void createPanelComponents() {
		if (LOG.isDebugEnabled()) {
			LOG.debug("createPanelComponents");
		}

		/* menu librairie composant */
		OMenuBar container = new OMenuBar("menuFilAriane");
		for (final TabList tab : TabList.values()) {
			container.add(new BookmarkablePageLink<Void>(tab.toLinkString(), tab.getClassPage()));
			add(container);
		}
	}

	/**
	 * List of available tabs and wicket Page to invoke
	 * 
	 */
	public enum TabList {
		HOME_TAB("homeTab", HomePage.class), MARKET_TAB("marketTab", MarketPage.class);

		private Class<? extends Page> classPage;
		private String markupString;

		/**
		 * constructor
		 */
		private TabList(String m, Class<? extends Page> c) {
			this.markupString = m;
			this.classPage = c;
		}

		/**
		 * 
		 * @return the wicket page associated to the selected tab
		 */
		public Class<? extends Page> getClassPage() {
			return this.classPage;
		}

		/**
		 * 
		 * @return the markup String associated to the selected tab
		 */
		public String getMarkupString() {
			return this.markupString;
		}

		/**
		 * @return the string to be used for BookmarkablePageLink Example : HOME_TAB returns homeTabLink
		 */
		private String toLinkString() {
			StringBuilder sb = new StringBuilder(getMarkupString());
			sb.append("Link");
			return sb.toString();
		}

	}

}